<?php


function logout($username, $type)
{
    $_SESSION = array();
    if(ini_get("session.use_cookies"))
    {
        $params = session_get_cookie_params();
        setcookie(session_name(), '',time()-42000, $params["path"], 
                $params["domain"],$params["secure"], $params["httponly"]);
    }
    
    session_destroy();
    if($type == 'json')
    {
        return GenericResponseJSON(1, "Success!");
    }
    else if($type == 'xml')
    {
       return GenericResponseXML(1, "Success!");
    }
}
function login($username, $password, $con, $type)
{  
    if(!$username)
    {
        $username = " ";
    }

    if(!$password)
    {
         $password = " ";
    }
    $query = "select ID from projects.user where name = '$username' and pass = '$password'";
    //call fatcowga_salesTracker.login('$username','$password');";

    $result = mysqli_query($con,$query);

    if(!$result) 
    {
        die("mysql error: ".mysql_error()."[$query]");
    }
     
     while($row = mysqli_fetch_assoc($result))
    {
        $resultValue = $row['ID'];
      
    }

    if($resultValue)
    {      
       
      $_SESSION['username'] = $username;   
      $_SESSION['s_uid'] = $resultValue;
      $session = session_id();
      session_start();
      
      if($type == 'json')
      {
        return LoginResponseJSON(1, "Success!",$resultValue,session_id());
      }
      else if($type == 'xml')
      {
        return  LoginResponseXML(1, "Success!",$resultValue,session_id());
      }
    }
    else
    {
       if($type == 'json')
      {
        return GenericResponseJSON(2, "Invalid username or password!");
      }
      else if($type == 'xml')
      {
          return GenericResponseXML(2, "Invalid username or password!");
      }
       
    }
}

?>
